import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service

path = Service('./chromedriver')
# 打开浏览器，返回浏览器对象
driver = webdriver.Chrome(service=path)
# 打开百度首页
driver.get('https://www.baidu.com/')
# 等待2s
time.sleep(2)
# 窗口最小化
driver.minimize_window()
time.sleep(2)
# 自定义窗口宽、高
driver.set_window_size(1200, 800)
time.sleep(2)
# 最大化窗口
driver.maximize_window()
time.sleep(2)
# 打开另一个页面
driver.get(
    'https://www.baidu.com/s?wd=%E6%8E%A2%E5%AF%BB%E2%80%9C%E4%BA%BA%E2%80%9D%E5%AD%97%E7%9A%84%E6%BC%94%E5%8F%98%E5%8E%86%E7%A8%8B&sa=fyb_n_homepage&rsv_dl=fyb_n_homepage&from=super&cl=3&tn=baidutop10&fr=top1000&rsv_idx=2&hisfilter=1')
time.sleep(2)
# 后退
driver.back()
time.sleep(2)
# 页面刷新
driver.refresh()
time.sleep(2)
# 前进
driver.forward()
time.sleep(2)
# 关闭选项卡
driver.close()
time.sleep(2)
# 关闭浏览器
driver.quit()
